using System.Collections;
using System.Collections.Generic;
using UnityEngine;




public class GameHelper
{
    public static Camera MainCamera;
    public static Camera NodeCamera;
    public static Camera UICamera;
    public static bool TouchAtNode = false;



    public static float ScaleRate = 0;
    public static int DESINE_FACT_W = 750;
    public static int DESINE_FACT_H = 1334;
    public static float DESINE_W = 7.5f;
    public static float DESINE_H = 13.34f;


    // public static void SetCemeraFitSize(CinemachineVirtualCamera camera)
    // {
    //     //适配规则 大于9:13.5的（也就是比这个更靠近正方形的机器）左右留黑边 
    //     float wdh = Screen.width * 1f / Screen.height;

    //     float DESINE_W = 9;
    //     //float DESINE_H = 16;

    //     if (9f / 20.48f <= wdh && wdh <= 9f / 13.5f)
    //     {
    //         //Screen.height / (Screen.width / DESINE_W) 这一句意思是 把 设计分辨率 变成  H/9（H比9）的比例
    //         //只要比例不变
    //         // camera.orthographicSize = Screen.height / (Screen.width / DESINE_W) / 2;// 保证宽度填满
    //         camera.m_Lens.OrthographicSize = Screen.height / (Screen.width / DESINE_W) / 2;// 保证宽度填满
    //         ScaleRate = DESINE_FACT_W / Screen.width;
    //     }
    //     else
    //     {
    //         if (9f / 20.48f > wdh)//更靠近长方形，左右填满
    //         {
    //             camera.m_Lens.OrthographicSize = Screen.height / (Screen.width / DESINE_W) / 2;// 保证宽度填满
    //             ScaleRate = DESINE_FACT_W / Screen.width;
    //         }

    //         if (wdh > 9f / 13.5f)//更靠近正方形，上下填满 
    //         {
    //             camera.m_Lens.OrthographicSize = 16 / 2;
    //             ScaleRate = DESINE_FACT_H / Screen.height;
    //         }
    //     }
    // }

    public static void SetCemeraFitSize(Camera camera)
    {
        //适配规则 大于9:13.5的（也就是比这个更靠近正方形的机器）左右留黑边 
        float wdh = Screen.width * 1f / Screen.height;

        //float DESINE_H = 16;

        if (9f / 20.48f <= wdh && wdh <= 9f / 13.5f)
        {
            //Screen.height / (Screen.width / DESINE_W) 这一句意思是 把 设计分辨率 变成  H/9（H比9）的比例
            //只要比例不变
            camera.orthographicSize = Screen.height / (Screen.width / DESINE_W) / 2;// 保证宽度填满
            ScaleRate = DESINE_FACT_W / Screen.width;
        }
        else
        {
            if (9f / 20.48f > wdh)//更靠近长方形，左右填满
            {
                camera.orthographicSize = Screen.height / (Screen.width / DESINE_W) / 2;// 保证宽度填满
                ScaleRate = DESINE_FACT_W / Screen.width;
            }

            if (wdh > 9f / 13.5f)//更靠近正方形，上下填满 
            {
                camera.orthographicSize = 16 / 2;
                ScaleRate = DESINE_FACT_H / Screen.height;
            }
        }
    }

    
#region 声音处理

    public static float bgmVolume = 0.5f;
    public static float seVolume = 0.5f;

    public static void PlayBgm(AudioSource audio, float volume) {
        if (volume > 0) {
            if (audio.isPlaying == false) {
                audio.loop = true;
                audio.Play();
            }
        }
        else {
            audio.Stop();
        }
    }

    public static void PlayBgm(AudioSource audio) {
        if (bgmVolume > 0) {
            if (audio.isPlaying == false) {
                audio.loop = true;
                audio.Play();
            }
        }
        else {
            audio.Stop();
        }
    }

     public static void PlaySE(AudioSource soundPlayer, string seName) {
        if (seVolume > 0) {
            AudioClip clip = Resources.Load<AudioClip>(seName);
            soundPlayer.clip = clip;
            soundPlayer.PlayOneShot(clip);
        }
    }

#endregion



}
